package com.keepmoving.web;

import com.keepmoving.po.Commit;
import com.keepmoving.po.Reply;
import com.keepmoving.po.User;
import com.keepmoving.service.CommitService;
import com.keepmoving.service.ReplyService;
import com.keepmoving.service.UserService;
import com.keepmoving.vo.CommitBO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 魏范彬
 * 回复控制器
 */
@Controller
public class ReplyController {

    @Resource
    CommitService commitService;

    @Resource
    ReplyService replyService;

    @Resource
    UserService userService;


    @RequestMapping("/toreply")
    public String toreply(int id, Model model){
        model.addAttribute("id",id);
        return "reply";
    }

    @RequestMapping("/reply")
    public String reply(@ModelAttribute CommitBO commitBO, HttpSession session){
        System.out.println("================");
        Commit commit=new Commit();
        commit.setcSummary(commitBO.getcSummary());
        commit.setlId(commitBO.getlId());
        commit.setcId(commitBO.getcId());
        commit.setLastId(commitBO.getLastId());
        commitService.insert(commit);
        int oId=commit.getoId();
        System.out.println(oId);
        List<CommitBO> commitBOList = commitService.findBycIdBo(commitBO.getcId(),commitBO);
        System.out.println(commitBOList.toString());
        session.setAttribute("commitBOList",commitBOList);
        session.setAttribute("oId",oId);
        return "redirect:/commitreply.action";
    }
}
